package com.hooper.security.custom;

import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import static com.hooper.constant.UserConstant.EXTRA_SALT;

@Component
public class CustomMd5PasswordEncoder implements PasswordEncoder {

    public String encode(CharSequence rawPassword) {
        return MD5Encoder.encode((rawPassword.toString() + EXTRA_SALT).getBytes());
    }

    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(MD5Encoder.encode((rawPassword.toString() + EXTRA_SALT).getBytes()));
    }
}